﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Objectifs : MonoBehaviour {

	// Properties
	//
	//

	public string Title = "Objective";
	public string Description = "What to do";

	public float minBuild = 0;
	public float minMood = -550f;
	public float minPop = 0;

	public float maxBuild = 10000;
	public float maxMood = 350;
	public float maxPop = 10000;

	public int minActionBuild = 0;
	public int minActionMood = 0;
	public int minActionPop = 0;

	public int maxActionBuild = 10;
	public int maxActionMood = 10;
	public int maxActionPop = 10;

	public bool Done = false;

	// Methods
	//
	//

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public bool CheckIfSuccess(Manager manager, List<Manager.Actions> actions){

		bool res = true;

		//Debug.Log("--------------------------------------------------------------");
		//Debug.Log("Objectifs.CheckIfSuccess - Name "+this.Title);


		// If a condition is not met
		if(manager.Building < this.minBuild || manager.Building > this.maxBuild){
			  
			//Debug.Log("Objectifs.CheckIfSuccess - Building level not checked");
			res = false;
		}
		if(manager.Population < this.minPop || manager.Population > this.maxPop){
			//Debug.Log("Objectifs.CheckIfSuccess - Pop level not checked");
			res = false;
		}
		if(manager.Mood < this.minMood || manager.Mood > this.maxMood){
			//Debug.Log("Objectifs.CheckIfSuccess - Mood level not checked");
			res = false;
		}


		// Compte des actions
		int actionBuild = 0;
		int actionMood = 0;
		int actionPop = 0;

		for(int i=0; i< actions.Count; i++){

			if(actions[i] == Manager.Actions.Build){
				actionBuild ++;
			}
			else if(actions[i] == Manager.Actions.Mood){
				actionMood++;
			}
			else if(actions[i] == Manager.Actions.Time){
				actionPop ++;
			}

		}

		//Debug.Log("Objectifs.CheckIfSuccess - ActionBuild "+actionBuild+" ActionMood "+actionMood+" ActionPop "+actionPop);

		// If a condition is not met
		if(actionBuild < this.minActionBuild || actionBuild >this.maxActionBuild || actionMood < this.minActionMood || actionMood > this.maxActionMood || actionPop < this.minActionPop || actionPop > this.maxActionPop ){
			//Debug.Log("Objectifs.CheckIfSuccess - Nombre action not met");
			res = false;
		}
		if(!this.Done){
			this.Done = res;
		}

		return res;

	}


}
